Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[added] onActiveStateChange, onCancelledTransition, onTransitionError Routes props #152

Merged
merged 1 commit into from
Aug 14, 2014

Conversation

mjackson
Copy link
Member

Also, removed Routes.handleAsyncError and Routes.handleCancelledTransition.

This PR exposes these handlers as props so they can be overridden by users. The onTransitionError prop is especially useful since it permits users to attach their own error handlers instead of using the default error handler that just throws (see #151).

I've written tests for these new features that all pass when I run them alone. However, when I run npm test locally there are 3 failing tests, but I'm not convinced that any of them have to do with my changes. I've digged around quite a bit but can't figure out what's going on in the DOM while the tests are running.

@rpflorence Since you're more experienced with karma than I am (and writing DOM tests in general) I thought you might be able to take a look?

@mjackson
Copy link
Member Author

Just FYI, here is the karma output for the failing specs:

Firefox 27.0.0 (Mac OS X 10.9) a cancelled transition triggers onCancelledTransition FAILED
\       Error: Invariant Violation: replaceState(...): Can only update a mounted or mounting component. (/Users/michael/Projects/react-router/specs/main.js:2760)
    process.on/global.onerror@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:5738

Firefox 27.0.0 (Mac OS X 10.9) when a new path is pushed to the URL has the correct path FAILED
    "/" deepEqual "/a/b/c"
    wrapAssertion/<@/Users/michael/Projects/react-router/specs/main.js:2800
    @/Users/michael/Projects/react-router/specs/main.js:751
    callFn@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4338
    Runnable.prototype.run@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4331
    Runner.prototype.runTest@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4728
    next/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4806
    next@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4653
    next/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4663
    next@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4601
    next/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4625
    done@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4300
    callFn@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4343
    Runnable.prototype.run@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4331
    next@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4613
    Runner.prototype.hook/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4630
    timeslice@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:5763

Firefox 27.0.0 (Mac OS X 10.9) when registering a route with the same name as another route throws an error FAILED
    Missing expected exception (Error)..
    _throws@/Users/michael/Projects/react-router/specs/main.js:2465
    assert.throws@/Users/michael/Projects/react-router/specs/main.js:2482
    wrapAssertion/<@/Users/michael/Projects/react-router/specs/main.js:2800
    @/Users/michael/Projects/react-router/specs/main.js:716
    callFn@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4338
    Runnable.prototype.run@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4331
    Runner.prototype.runTest@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4728
    next/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4806
    next@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4653
    next/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4663
    next@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4601
    next/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4625
    done@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4300
    callFn@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4343
    Runnable.prototype.run@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4331
    next@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4613
    Runner.prototype.hook/<@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:4630
    timeslice@/Users/michael/Projects/react-router/node_modules/mocha/mocha.js:5763

Firefox 27.0.0 (Mac OS X 10.9): Executed 53 of 52 (3 FAILED) (0.176 secs / 0.088 secs)

@ryanflorence
Copy link
Member

Cool, I'll take a look when I get a spare cycle or two. Thanks for the tests, we need to start taking tests more seriously and I think the harness falls on my shoulders, I'll try to make it friendlier. After the next release we need to beef up our tests too.

Does onCancelledTransition fire when the user clicks between two routes really fast and the transitions hooks haven't resolved yet?

@mjackson
Copy link
Member Author

onCancelledTransition is the function that gets called when a transition is aborted/redirected. The default is for the router to handle the abort/redirect, but we'll need the hook on the server side to do things like 404 and 302.

@ryanflorence
Copy link
Member

I got this passing ... its really strange, I need to spend some time making our test stuff 1000% better.

@ryanflorence
Copy link
Member

👎 auth flow example is broken, click on the dashboard before being logged in.

@mjackson
Copy link
Member Author

mjackson commented Aug 6, 2014

@rpflorence thanks. i'll take a look.

@ryanflorence
Copy link
Member

👎 also the transitions example is broken, click on "form" then click on "dashboard" then click "cancel" in the alert. BOOM

@mjackson
Copy link
Member Author

mjackson commented Aug 6, 2014

@rpflorence did you have any commits to add? or it just passes on your machine?

@ryanflorence
Copy link
Member

I amended and force pushed the changes to the branch

…outes props

Also, removed Routes.handleAsyncError and Routes.handleCancelledTransition
@mjackson mjackson merged commit 6878120 into master Aug 14, 2014
@mjackson mjackson deleted the routes-props branch August 14, 2014 22:57
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants